home *** CD-ROM | disk | FTP | other *** search
/ Champak 106 / Vol 106.iso / games / rain_for.swf / scripts / __Packages / CitizenHandler.as < prev    next >
Encoding:
Text File  |  2010-04-12  |  3.2 KB  |  122 lines

  1. class CitizenHandler
  2. {
  3.    var location;
  4.    var oHandler;
  5.    var totalThresh;
  6.    var aBobo;
  7.    var baseThrust;
  8.    var arcRange;
  9.    var lowerArc;
  10.    var oBuildings;
  11.    var nRelease = 0;
  12.    var cRelease = 0;
  13.    var highThresh = 2;
  14.    var lowThresh = 8;
  15.    var levelInc = 0.3;
  16.    var windChance = 3;
  17.    var bBobo = false;
  18.    var nTotalCitizens = 0;
  19.    var nCitizenCap = 5;
  20.    function CitizenHandler(loc)
  21.    {
  22.       this.location = loc;
  23.       this.oHandler = new smashing.ClipHandler(loc);
  24.       this.totalThresh = this.lowThresh - this.highThresh;
  25.       this.aBobo = [loc._parent.mcBobo0,loc._parent.mcBobo1];
  26.       this.aBobo[0].oCitizens = this;
  27.       this.aBobo[1].oCitizens = this;
  28.       this.baseThrust = new smashing.Point(-210,0);
  29.       this.arcRange = 0.7853981633974483;
  30.       this.lowerArc = 0.47123889803846897;
  31.    }
  32.    function update(nElapsed)
  33.    {
  34.       var _loc4_ = this.oHandler.clips;
  35.       var _loc5_ = _loc4_.length;
  36.       var _loc3_ = undefined;
  37.       var _loc2_ = 0;
  38.       while(_loc2_ < _loc5_)
  39.       {
  40.          _loc3_ = _loc4_[_loc2_];
  41.          if(_loc3_ != null)
  42.          {
  43.             _loc3_.update(nElapsed);
  44.          }
  45.          _loc2_ = _loc2_ + 1;
  46.       }
  47.       this.cRelease += nElapsed;
  48.       if(this.cRelease >= this.nRelease)
  49.       {
  50.          this.cRelease = 0;
  51.          this.addCitizen();
  52.       }
  53.    }
  54.    function render()
  55.    {
  56.       var _loc4_ = this.oHandler.clips;
  57.       var _loc5_ = _loc4_.length;
  58.       var _loc3_ = undefined;
  59.       var _loc2_ = 0;
  60.       while(_loc2_ < _loc5_)
  61.       {
  62.          _loc3_ = _loc4_[_loc2_];
  63.          if(_loc3_ != null)
  64.          {
  65.             _loc3_.render();
  66.          }
  67.          _loc2_ = _loc2_ + 1;
  68.       }
  69.    }
  70.    function addCitizen()
  71.    {
  72.       if(this.nTotalCitizens > this.nCitizenCap)
  73.       {
  74.          return undefined;
  75.       }
  76.       this.nTotalCitizens = this.nTotalCitizens + 1;
  77.       var _loc2_ = this.aBobo[Number(this.bBobo)];
  78.       if(_loc2_._currentframe == 1)
  79.       {
  80.          this.aBobo[Number(this.bBobo)].gotoAndStop("in");
  81.          this.bBobo = !this.bBobo;
  82.       }
  83.    }
  84.    function toss(pToss)
  85.    {
  86.       var _loc3_ = new smashing.Point(pToss.x - smashing.Viewport.centerX,pToss.y - smashing.Viewport.centerY);
  87.       _loc3_.x += smashing.Viewport.x;
  88.       _loc3_.y += smashing.Viewport.y;
  89.       var _loc4_ = this.baseThrust.rotate(Math.random() * this.arcRange + this.lowerArc);
  90.       var _loc2_ = this.oHandler.addClip("mcCitizen");
  91.       _loc2_.x = _loc3_.x;
  92.       _loc2_.y = _loc3_.y;
  93.       _loc2_.m = _loc4_;
  94.       _loc2_.oCitizenHandler = this;
  95.       _loc2_.oBuildings = this.oBuildings;
  96.       _loc2_.render();
  97.    }
  98.    function removeCitizen(o)
  99.    {
  100.       this.nTotalCitizens = this.nTotalCitizens - 1;
  101.       this.oHandler.removeClip(o);
  102.    }
  103.    function setRatio(nRatio)
  104.    {
  105.       nRatio = 1 - nRatio;
  106.       this.nRelease = nRatio * this.totalThresh + this.highThresh;
  107.    }
  108.    function reset()
  109.    {
  110.       this.oHandler.removeAllClips();
  111.    }
  112.    function setLevel(nLevel)
  113.    {
  114.       nLevel -= 1;
  115.       this.totalThresh = this.lowThresh - this.highThresh - nLevel * this.levelInc;
  116.       if(this.totalThresh < 0)
  117.       {
  118.          this.totalThresh = 0;
  119.       }
  120.    }
  121. }
  122.